﻿using IR.Controller.ModelControllers;
using IR.WPF.ViewModels.LandingViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace IR.WPF.UI.ViewModels
{
    public class VMNote : ViewModelBase
    {
        private CNote _note;
        private ICommand _editCommand;

        public VMNote(CNote noteToUse)
        {
            _note = noteToUse;
        }

        #region **Properties**
        public string Username
        {
            get { return _note.UserCreated.Username; }
        }

        public string DateCreated
        {
            get { return _note.DateCreated.ToString(); }
        }

        public string Notes
        {
            get { return _note.Notes; }
        }

        public CNote NoteController
        {
            get { return _note; }
        }
        #endregion

        #region **Commands**
        /// <summary>
        /// Gets a command defined for Edit
        /// </summary>
        public ICommand Edit
        {
            get
            {
                if (_editCommand == null)
                    _editCommand = new RelayCommand(p => EditFunction(p as Control), p => CanEdit(p as Control));

                return _editCommand;
            }
        }
        #endregion

        #region **Command Functions**
        protected void EditFunction(Control sender)
        {
            // Get a reference to the Window that contained the sender Control
            Window window = Window.GetWindow(sender);

            MessageBox.Show("An edit Window");
        }
        #endregion

        #region **CanRun Functions**
        protected bool CanEdit(Control sender)
        {
            return true;
        }
        #endregion
    }
}
